var grid;
function initGrid(staffRoleId){
  grid = $("#maingrid").ligerGrid({
    url:HTR.U('index/salesremind/pageQuery'),
    pageSize:HTR.pageSize,
    pageSizeOptions:HTR.pageSizeOptions,
    height:'99%',
        width:'100%',
        minColToggle:6,
        rownumbers:true,
        columns: [
          { display: '姓名', name: 'user_name', isSort: false,width:150},
          { display: '提醒', name: 'desc', isSort: false},
          { display: '日期', name: 'remindTime', isSort: false,width:150},
          { display: '操作', name: 'op',width:100,isSort: false,render: function (rowdata, rowindex, value){
              var h = "";
              if(HTR.GRANT.WXFTX_01 && (staffRoleId == 1 || staffRoleId == 3)){
                if(rowdata['is_read']){
                  h += "<a class='read1'>已读</a> ";
                }else{
                  h += "<a href='javascript:changeRead(" + rowdata['remind_id'] + ")'>已读</a> ";
                }
              }
              if(HTR.GRANT.WXFTX_02 && (staffRoleId == 1 || staffRoleId == 3))h += "<a href='javascript:del(" + rowdata['remind_id'] + ")'>删除</a> "; 
              return h;
          }}
        ]
    }); 
}

function pageQuery(){
	var query = HTR.getParams('.query');
	grid.set('url',HTR.U('index/salesremind/pageQuery',query));
}


function changeRead(id){
  $.post(HTR.U('index/salesremind/changeRead'), {'id':id}, function(data, textStatus){
    var json = HTR.toIndexJson(data);
      if(json.status=='1'){
          HTR.msg("操作成功",{icon:1});
          grid.reload();
      }else{
          HTR.msg(json.msg,{icon:2});
      }
  })
}

function del(id){
  var box = HTR.confirm({content:"您确定要删除该消息吗?",yes:function(){
   var loading = HTR.msg('正在提交数据，请稍后...', {icon: 16,time:60000});
   $.post(HTR.U('index/salesremind/del'),{id:id},function(data,textStatus){
        layer.close(loading);
        var json = HTR.toIndexJson(data);
        if(json.status=='1'){
            HTR.msg(json.msg,{icon:1});
            layer.close(box);
            grid.reload();
        }else{
            HTR.msg(json.msg,{icon:2});
        }
      });
    }});
}